<template>
    <div class="goods-item" @click="goDetail">
        <div class="item-img">
            <img :src="item.src" alt="商品图片" />
        </div>
        <div class="item-info">
            <p class="item-title">{{ item.title }}</p>
            <p class="item-decip">{{ item.decip }}</p>
            <div class="price">
                <span class="price-now">￥{{ item.nprice }}</span>
                <span class="price-old">￥{{ item.oprice }}</span>
            </div>
        </div>
    </div>
</template>

<script setup>
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'

const props = defineProps({
    item: {
        type: Object,
        required: true
    },
    toDetail: {
        type: Boolean,
        default: false
    }
})

const router = useRouter()

const goDetail = () => {
    if (props.toDetail) {
        router.push({ path: '/page3', query: { id: props.item.id } })
    }
}
</script>

<style scoped>
.goods-item {
    width: 300px;
    height: 350px;
    background-color: #fff;
    margin: 8px 0 0 8px;
    border-radius: 10px;
}

.item-img {
    width: 300px;
    height: 200px;
}

.item-img img {
    width: 300px;
    height: 200px;
    border-radius: 10px;
    object-fit: contain;
}

.item-info {
    width: 100%;
    height: 150px;
    background-color: #fff;
    border-radius: 10px;
}

.item-info  .item-title {
    display: block;
    height: 30px;
    text-align: center;
    line-height: 30px;
    font-size: 16px;
    font-weight: bolder;
    color: #333;
    margin: 0;
    background-color: aqua;
}

.item-info  .item-decip {
    display: block;
    height: 25px;
    text-align: center;
    line-height: 25px;
    font-size: 10px;
    color: #666;
    margin: 0;
    background-color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.price {
    text-align: center;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.price-now {
    font-size: 14px;
    color: #333;
    font-weight: bolder;
}

.price-old {
    text-decoration: line-through;
    color: #f61515;
    font-size: 12px;
    margin-left: 10px;
}
</style>